package com.reform.service.impl;

import com.reform.pojo.expert.Label;
import com.reform.mapper.LabelMapper;
import com.reform.res.Result;
import com.reform.res.ResultCode;
import com.reform.service.ILabelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mortale
 * @since 2021-08-12
 */
@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements ILabelService {

    @Autowired
    LabelMapper labelMapper;

    @Override
    public Result creatLabel(String labelName) throws SQLException {
        if (labelMapper.insert(new Label(null, labelName)) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.success(ResultCode.FAILURE);
    }

    @Override
    public Result deleteLabel(Integer labelId) throws SQLException {
        if (labelMapper.deleteById(labelId) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.success(ResultCode.FAILURE);
    }

    @Override
    public Result updateLabel(Integer labelId, String labelName) throws SQLException {
        if (labelMapper.updateById(new Label(labelId, labelName)) > 0)
            return Result.success(ResultCode.SUCCESS);
        return Result.success(ResultCode.FAILURE);
    }

    @Override
    public Result getLabels() throws SQLException {
        return Result.success(ResultCode.SUCCESS, labelMapper.selectList(null));
    }
}
